﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TechTalk.SpecFlow;

namespace BTS.Testing.TraceMonitor.BizUnitSteps.Tests.Steps
{
    [Binding]
    public class StepDefinitions
    {
        private const string TraceQueuePath = @".\private$\BTS.Testing.TraceMonitor";
#if DEBUG
        private const string TraceToolPath = @"..\..\..\BTS.Testing.TraceMonitor\bin\debug\BTS.Testing.TraceMonitor.exe";
#else
        private const string TraceToolPath = @"..\..\..\BTS.Testing.TraceMonitor\bin\release\BTS.Testing.TraceMonitor.exe";
#endif
        [BeforeScenario("StartTraceMonitor")]
        public void SetupTraceMonitor()
        {
            new StartRealtimeEventTrace()
            {
                TraceToolPath = TraceToolPath
            }.Execute();
        }
        [AfterScenario("StopTraceMonitor")]
        public void TearDownTraceMonitor()
        {
            new StopRealtimeEventTrace().Execute();
        }
        [Given(@"A running trace monitor")]
        public void GivenARunningTraceMonitor()
        {
            Console.WriteLine("Assume this is running");
        }

        [Then(@"I can check for the existance of the event by polling all events")]
        public void ThenICanCheckForTheExistanceOfTheEventByPollingAllEvents()
        {
            new PollForEvent()
            {
                DeleteAfterFound = false,
                IncludeBodyCompare = true,
                QueuePath = TraceQueuePath,
                RegEx = "This is a test cat team event",
                TimeoutSeconds = 10
            }.Execute();
        }

        [Then(@"I can check for the existance of the event through the bizunit steps")]
        public void ThenICanCheckForTheExistanceOfTheEventThroughTheBizunitSteps()
        {
            new PollForNextEvent()
            {
                DeleteAfterFound = false,
                IncludeBodyCompare = true,
                QueuePath = TraceQueuePath,
                RegEx = "This is a test cat team event",
                TimeoutSeconds = 10
            }.Execute();
        }

        [Then(@"I can delete the event")]
        public void ThenICanDeleteTheEvent()
        {
            new PollForEvent()
            {
                DeleteAfterFound = true,
                IncludeBodyCompare = true,
                QueuePath = TraceQueuePath,
                RegEx = "This is a test cat team event",
                TimeoutSeconds = 10
            }.Execute();
        }

        [Then(@"the trace monitor should capture the logged event")]
        public void ThenTheTraceMonitorShouldCaptureTheLoggedEvent()
        {
            Console.WriteLine("This is picked up in other steps");
        }

        [Then(@"the trace monitor should log event details to msmq")]
        public void ThenTheTraceMonitorShouldLogEventDetailsToMsmq()
        {
            Console.WriteLine("This is picked up in other steps");
        }

        [When(@"execute some code which logs via the CAT team logging framework")]
        public void WhenExecuteSomeCodeWhichLogsViaTheCATTeamLoggingFramework()
        {
            Microsoft.BizTalk.CAT.BestPractices.Framework.Instrumentation.TraceManager.CustomComponent.TraceInfo(
                "This is a test cat team event");


            Microsoft.BizTalk.CAT.BestPractices.Framework.Instrumentation.TraceManager.WorkflowComponent.TraceIn();


            Microsoft.BizTalk.CAT.BestPractices.Framework.Instrumentation.TraceManager.ServiceComponent.TraceIn();
        }
    }
}
